package com.project.logistics.mapper;

import com.project.logistics.bean.Evaluate;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by94988 on 2021/3/30 15:58
 */

@Mapper
public interface EvaluateMapper {


    @Select("select * from evaluate where repairs_id = #{repairsId}")
    Evaluate fingEvaluateById(int repairsId);

    //删除当前用户当前评论
    @Update("update evaluate set evaluate_comment = '该评论已删除' where repairs_id = #{repairsId}")
    int deleteComment(int repairsId);

    @Update("update evaluate set answer = '该回复已删除' where repairs_id = #{repairsId}")
    int deleteAnswer(int repairsId);



    //查看当前用户当前报修评价
    @Select("select * from evaluate WHERE repairs_id=#{repairsId}")
    Evaluate getCommentById(int repairsId) ;

    //添加当前用户报修评论
    @Insert("insert into evaluate(`repairs_id`,`evaluate_time`,`evaluate_score`,`evaluate_comment`) values(#{repairsId},#{evaluateTime},#{evaluateScore},#{evaluateComment})")
    void insertEvaluate(Evaluate evaluate);

    //修改当前用户当前报修评论
    @Update("update evaluate set evaluate_time=#{evaluateTime},evaluate_score=#{evaluateScore},evaluate_comment=#{evaluateComment} where repairs_id=#{repairsId}")
    void updateEvaluate(Evaluate evaluate);

    //查看当前维修人所有维修评论
    @Select("select e.repairs_id,evaluate_time,evaluate_score,evaluate_comment from evaluate e LEFT JOIN repairs r ON e.repairs_id=r.repairs_id where service_user_id=#{RepairsmanId}")
    List<Evaluate> getCommentsByRepairsmanId(String repairsmanId);


    //添加维修人回复
    @Update("update evaluate set answer_time=#{answerTime},answer=#{answer} where repairs_id=#{repairsId}")
    void updateEvaluateReply(Evaluate evaluate);
}
